/* **********************************************************************************
*
* Copyright (c) Microsoft Corporation. All rights reserved.
*
* This source code is subject to terms and conditions of the Shared Source License
* for DSL Editor PowerToy. A copy of the license can be found in the License.htm file
* at the root of this distribution. If you can not locate the Shared Source License
* for DSL Editor PowerToy, please obtain a copy from: http://www.codeplex.com/dsltreegrideditor/Project/License.aspx.
* By using this source code in any fashion, you are agreeing to be bound by
* the terms of the Shared Source License for DSL Editor PowerToy.
*
* You must not remove this notice, or any other, from this software.
*
* **********************************************************************************/
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Text;

using Microsoft.VisualStudio.Modeling;
using Microsoft.VisualStudio.Modeling.Diagrams;

using DslEditorPowerToy.Controls;

namespace DslEditorPowerToy.Languages.EditorConfiguration
{
    #region Diagram Appearance
    partial class EditorConfigurationDiagram
    {
        #region Protected Methods
        protected override void InitializeInstanceResources()
        {
            base.InitializeInstanceResources();

            //Add background image
            DrawingHelper.AddBackgroundImageBanner(this.ShapeFields, Resources.DomainBackground);
        }
        #endregion
    }
    #endregion

    #region Property Change Settings
    partial class EditorConfigurationDiagram
    {
        protected override void InitializeResources(StyleSet classStyleSet)
        {
            base.InitializeResources(classStyleSet);

            //Register handler for property changes
            EditorConfigurationDiagram.AssociateValueWith(this.Store, DslDomain.HostingStyleDomainPropertyId);
        }
        /// <summary>
        /// Handles property changes
        /// </summary>
        /// <param name="e"></param>
        protected override void OnAssociatedPropertyChanged(PropertyChangedEventArgs e)
        {
            //Check which property has changed
            if ("HostingStyle".Equals(e.PropertyName))
            {
                //Initialise Navigation style for appropriate Hosting style
                DslDomain domain = this.Subject as DslDomain;

                EditorHostStyle oldStyle = (EditorHostStyle)Enum.Parse(typeof(EditorHostStyle), e.OldValue.ToString(), true);
                EditorHostStyle newStyle = (EditorHostStyle)Enum.Parse(typeof(EditorHostStyle), e.NewValue.ToString(), true);

                using (Transaction transaction = this.Store.TransactionManager.BeginTransaction(Resources.Transaction_UpdateDefaultNavigation))
                {
                    if ((EditorHostStyle.ToolWindow == oldStyle)
                        && (EditorHostStyle.Designer == newStyle))
                        domain.NavigationStyle = NavigationOrientationStyle.HorizontalTabsBottom;
                    if ((EditorHostStyle.Designer == oldStyle)
                        && (EditorHostStyle.ToolWindow == newStyle))
                        domain.NavigationStyle = NavigationOrientationStyle.Vertical;

                    transaction.Commit();
                }
            }

            base.OnAssociatedPropertyChanged(e);
        }
    }
    #endregion
}
